$(function () {
   TimeDown(900);
  /*
   时间倒计时
   TimeDown.js
   */
  function TimeDown(totalSeconds) {
    //取模（余数）
    var modulo = totalSeconds % (60 * 60 * 24);
    //小时数
    var hours = Math.floor(modulo / (60 * 60));
    modulo = modulo % (60 * 60);
    //分钟
    var minutes = Math.floor(modulo / 60);
    //秒
    var seconds = modulo % 60;
  
    //补零
    // hours = hours.toString().length == 1 ? '0' + hours : hours;
    // minutes = minutes.toString().length == 1 ? '0' + minutes : minutes;
    seconds = seconds.toString().length == 1 ? '0' + seconds : seconds;
  
    //输出到页面
    $(".count-down-wrapper .time-left .minute").html(minutes);
    $(".count-down-wrapper .time-left .second").html(seconds);

    //延迟一秒执行自己
    if(hours == "00" && minutes == "00" && parseInt(seconds)-1<0){
        $(".modal-container").fadeIn(300);
        //获取订单号,删除订单
	  	var orderNum = $("#orderNum").val();
        $.ajax({
			url:"removeOrder.do",
			type:"get",
			data:{
				"orderNum":orderNum,
				"flag":1
			},
			dataType:"json",
			success:function(data){
			}
		})
    }else{
    	setTimeout(function () {
    		TimeDown(totalSeconds-1);
    	}, 1000);
    }
  }
  
  $(".right .modal-container .ok-btn").click(function(){
	  //发送请求
	  location.href = "index";
  });
  
  $(".right .pay-btn").click(function(){
	  //确认支付
	  $(".mask .modal-container").fadeIn(300);
  });
  
  //取消支付
  $(".mask .modal-container .cancel-btn").click(function(){
	  $(".mask .modal-container").fadeOut(300);
  });
  
  //确认支付
  $(".mask .modal-container .ok-btn").click(function(){
	  //获取订单号
	  var orderNum = $("#orderNum").val();
	  $.ajax({
			url:"pay.do",
			type:"get",
			data:{
				"orderNum":orderNum
			},
			dataType:"json",
			success:function(data){
			}
		});
	  $(".mask .modal-container").hide();
	  $(".pay-ok .modal-container").fadeIn(300);
  });
  
  //查看订单
  $(".pay-ok .modal-container .ok-btn").click(function(){
	  //获取uid
	  var uid = $("#uid").val();
	  location.href = "order.do?uid="+uid;
  });
  
  //返回首页
  $(".pay-ok .modal-container .back").click(function(){
	  location.href = "index";
  });
  
});

